package 牛客题霸;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class 最大数 {

    static List<Integer> res = new ArrayList<>();

    static List<String> ron = new ArrayList<>();

    public static String solve (int[] nums) {
        f(nums,nums.length,0);
        if(ron == null || ron.size() <= 0) {
            return "0";
        }
        Collections.sort(ron,(o1,o2) -> o2.compareTo(o1));
        return ron.get(0);
    }

    public static void f(int[] nums,int target,int cur) {
        if(target == cur) {
            StringBuilder strs = new StringBuilder();
            for (int i = 0; i < res.size(); i++) {
                strs.append(res.get(i));

            }
            ron.add(new BigInteger(strs.toString()).toString());
            return;
        }
        for (int i = 0; i <nums.length ; i++) {
            if(res.contains(nums[i])) {
                continue;
            }
            res.add(nums[i]);
            f(nums,target,cur + 1);
            res.remove(res.size() - 1);
        }
    }

    public static void main(String[] args) {
        int[] arr = new int[]{1,2,3,4,5,6,7,8,9,0};
        String solve = solve(arr);
        System.out.println(ron.toString());
        System.out.println(solve);
    }
}
